import request from '@/utils/axios'

// 优惠券模板
export interface CouponTemplateType {
  id: number
  name: string
  status: number
  totalCount: number
  takeLimitCount: number
  takeType: number
  usePrice: number
  productScope: number
  productScopeValues: number[]
  validityType: number
  validStartTime: Date
  validEndTime: Date
  fixedStartTerm: number
  fixedEndTerm: number
  discountType: number
  discountPercent: number
  discountPrice: number
  discountLimitPrice: number
  takeCount: number
  useCount: number
}
/**
 * 优惠券接口
 */
export const CouponApi = {
  // 删除优惠券
  delete: async (id: number) => {
    return await request.post({ url: `/promotion/coupon/delete?id=${id}`, is_mock: true })
  },
  // 获取优惠券分页
  page: async params => {
    return await request.get({
      url: '/promotion/coupon/page',
      params,
      is_mock: true
    })
  },
  // 发送优惠券
  send: async data => {
    return await request.post({
      url: '/promotion/coupon/send',
      data,
      is_mock: true
    })
  },
  // 优惠券模板
  Template: {
    // 创建优惠券模板
    create: async (data: CouponTemplateType) => {
      return await request.post({
        url: '/promotion/coupon-template/create',
        data,
        is_mock: true
      })
    },
    // 更新优惠券模板
    update: async (data: CouponTemplateType) => {
      return await request.post({
        url: '/promotion/coupon-template/update',
        data,
        is_mock: true
      })
    },
    // 更新优惠券模板状态
    updateStatus: async (id: number, status: [0, 1]) => {
      return await request.put({
        url: '/promotion/coupon-template/update-status',
        data: {
          id,
          status
        },
        is_mock: true
      })
    },
    // 删除优惠券模板
    delete: async (id: number) => {
      return await request.delete({ url: `/promotion/coupon-template/delete?id=${id}`, is_mock: true })
    },
    // 获取优惠券模板
    detail: async (id: number) => {
      return await request.get({
        url: '/promotion/coupon-template/get?id=' + id,
        is_mock: true
      })
    },
    // 查询优惠券模板
    page: async params => {
      return await request.get({
        url: '/promotion/coupon-template/page',
        params,
        is_mock: true
      })
    },
    // 查询指定优惠券模板
    list: async (ids: number[]) => {
      return await request.get({
        url: `/promotion/coupon-template/list?ids=${ids}`,
        is_mock: true
      })
    },
    // 导出优惠券模板
    export: async params => {
      return await request.get({
        url: '/promotion/coupon-template/export-excel',
        params,
        responseType: 'blob',
        is_mock: true
      })
    }
  }
}
